<template>
  <div class="invite_company_page">
    <div class="box_shallow search_box" style="font-size: 14px;">
      <el-row class="search_form">
        <el-col :span="6" class="col">
          <div class="key">关键字</div>
          <el-input v-model="form.keyword" placeholder="请输入关键字"></el-input>
        </el-col>
        <el-col :span="6" class="col">
          <div class="key">是否注册</div>
          <el-select class="value" v-model="form.registerEnterprise">
            <el-option value="">请选择</el-option>
            <el-option value="">是</el-option>
            <el-option value="">否</el-option>
          </el-select>
        </el-col>
        <el-col :span="6" class="col">
          <div class="key">企业状态</div>
          <el-select class="value" v-model="form.status">
            <el-option value="">请选择</el-option>
            <el-option value=""></el-option>
          </el-select>
        </el-col>
        <el-col :span="6" class="col">
          <div class="key">日期</div>
          <el-date-picker
            class="value"
            v-model="form.date"
            type="daterange"
            range-separator="至"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-col>
      </el-row>
      <el-button type="primary" class="search_btn" @click="search">搜索</el-button>
    </div>
    <div class="box_shallow table_box">
      <el-table :data="tableData" v-loading="loading">
        <el-table-column
          v-for="item in columns"
          :key="item.label"
          v-bind="item"
        >
        </el-table-column>
      </el-table>
      <Pagination
        :hidden="pagination.total === 0"
        :total="pagination.total"
        :page-size="pagination.pageSize"
        :current-page="pagination.pageNum"
        :limit="10"
        @pagination="paginationChange"
      />
    </div>
  </div>
</template>

<script>
import { inviteList } from '@/api/companyManage'
import Pagination from '@/components/Pagination'

export default {
  components: {
    Pagination,
  },
  data() {
    return {
      form: {
        keyword: '',
        registerEnterprise: '',
        status: '',
        date: [],
      },
      columns: [],
      tableData: [],
      loading: false,
      pagination: {
        total: 0,
        pageSize: 10,
        pageNum: 1,
      },
    }
  },
  created() {
    this.columns = [
      {
        type: 'index',
        label: '序号'
      },
      {
        prop: 'userName',
        label: '被邀企业账号'
      },
      {
        prop: 'beEnterpriseName',
        label: '被邀企业'
      },
      {
        prop: 'createTime',
        label: '邀请日期'
      },
      {
        prop: 'authenticate',
        label: '是否认证',
        formatter: (row, column, cellValue, index) => {
          // 是否认证 状态 0：否 1：是
          if (cellValue === '0') {
            return '否'
          } else {
            return '是'
          }
        }
      },
      {
        prop: 'authenticateTime',
        label: '注册日期'
      },
      {
        prop: 'status',
        label: '企业状态',
        formatter: (row, column, cellValue, index) => {
          // 状态 0：未认证 1：等待审核 2：已认证 3：认证失败
          switch (cellValue) {
            case '0':
              return '未认证'
            case '1':
              return '等待审核'
            case '2':
              return '已认证'
            case '3':
              return '认证失败'
          }
        }
      }
    ]
  },
  mounted() {
    this.inviteList()
  },
  methods: {
    search() {
      this.inviteList()
    },
    inviteList() {
      const { date, ...rest } = this.form
      this.loading = true
      inviteList({
        ...rest,
        dateStart: date?.[0] || '',
        dateEnd: date?.[1] || '',
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize
      }).then((res) => {
        this.loading = false
        this.tableData = res.rows
        this.pagination.total = res.total
      }).catch(() => {
        this.loading = false
      })
    },
    paginationChange({ page: pageNum, limit: pageSize }) {
      this.pagination.pageNum = pageNum
      this.pagination.pageSize = pageSize
      this.inviteList()
    },
  }
}
</script>

<style lang="scss" scoped>
@import '@/assets/styles/px2rem.scss';
.invite_company_page {
  .box_shallow {
    box-shadow: 0 1px 2px 0 rgba(1, 24, 70, 0.09);
    border-radius: 6px;
    background-color: #fff;
    margin-bottom: 16px;
  }
  .search_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 16px;
    .search_form {
      flex: 1 1 auto;
      .col {
        display: flex;
        align-items: center;
        .key {
          flex-shrink: 0;
          color: #777;
          font-size: 14px;
          width: 80px;
          text-align: right;
          margin-right: 10px;
        }
        .value {
          flex: 1 1 auto;
        }
      }
    }
    .search_btn {
      width: 120px;
      margin-left: 30px;
    }
  }
  .table_box {
    padding: 16px 16px 24px;
  }
}
</style>
